Skip to content

Conversation

@hylkest
Copy link

@hylkest hylkest commented Oct 27, 2025

With this change we can now use the modai system settings as context setting.

This helps with multi language websites to have seperate prompts for each context.

Copy link
Member

@theboxer theboxer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The support should be also extended into the modAI\API\Prompt\Vision endpoint


public function post(ServerRequestInterface $request): void
{
$contextKey = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default should be null

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$base = Settings::getTextSetting($this->modx, $field, 'base_prompt', $namespace, false);
$fieldPrompt = Settings::getTextSetting($this->modx, $field, 'prompt', $namespace);
$customOptions = Settings::getTextSetting($this->modx, $field, 'custom_options', $namespace, false);
$model = Settings::getTextSetting($this->modx, $field, 'model', $namespace, 'openai/gpt-4o-mini', $contextKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong arguments, instead of required you're passing model name

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$fieldPrompt = Settings::getTextSetting($this->modx, $field, 'prompt', $namespace);
$customOptions = Settings::getTextSetting($this->modx, $field, 'custom_options', $namespace, false);
$model = Settings::getTextSetting($this->modx, $field, 'model', $namespace, 'openai/gpt-4o-mini', $contextKey);
$temperature = (float)Settings::getTextSetting($this->modx, $field, 'temperature', $namespace , 0, $contextKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong arguments, the required one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$customOptions = Settings::getTextSetting($this->modx, $field, 'custom_options', $namespace, false);
$model = Settings::getTextSetting($this->modx, $field, 'model', $namespace, 'openai/gpt-4o-mini', $contextKey);
$temperature = (float)Settings::getTextSetting($this->modx, $field, 'temperature', $namespace , 0, $contextKey);
$maxTokens = (int)Settings::getTextSetting($this->modx, $field, 'max_tokens', $namespace, 0, $contextKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong arguments, the required one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$maxTokens = (int)Settings::getTextSetting($this->modx, $field, 'max_tokens', $namespace, 0, $contextKey);
$output = Settings::getTextSetting($this->modx, $field, 'base_output', $namespace, false, $contextKey);
$base = Settings::getTextSetting($this->modx, $field, 'base_prompt', $namespace, false, $contextKey);
$fieldPrompt = Settings::getTextSetting($this->modx, $field, 'prompt', $namespace, false, $contextKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prompt for field should be required, that's the whole reason for the generate button on those fields, that it'll get prompt from a system setting

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* @return string|null
*/
private static function getOption(modX $modx, string $namespace, string $field, string $area, string $setting): ?string
private static function getOption(modX $modx, string $namespace, string $field, string $area, string $setting, string $contextKey = 'web'): ?string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value for $contextKey should be null

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$handler = $modx;

if (!empty($contextKey)) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete the empty line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* @throws RequiredSettingException
*/
public static function getTextSetting(modX $modx, string $field, string $setting, string $namespace = 'modai', bool $required = true): ?string
public static function getTextSetting(modX $modx, string $field, string $setting, string $namespace = 'modai', bool $required = true, string $contextKey = ''): ?string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default for $contextKey should be null

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants